Data sort method utilizing finite difference tables

ABSTRACT

A sequence of information items, each of which has or can be assigned a numerical value, is sorted to obtain a list arranged in order of ascending or descending magnitude. This is accomplished by generating a difference table for the sequence and then interchanging various items of the sequence depending on the entries of the difference table.

United States Patent 1151 3,662,402 Bond et al. p 1 May 9, 1972 541 DATA SORT METHOD UTILIZING 2,901,732 8/1959 Canning ..340/174 F INITE DIFFERENCE TABLES OTHER PUBLICATIONS [72] Inventors: Kenneth L. Bond; James A. Schooley, both of Phoenix Ariz Number Sorting by Computer, I. A. ltskovlch et al., Cybernetics, v01. 1, pp. 93- 95, Sept.- Oct. 1965. Asslgneel Honeywdl Information Systems An Introduction to Sort Techniques," E. Opengart, Compu- Waltham, Massters and Automation, v61. 16, p. 24- 29, Feb. 1967. [22] Filed, 4 1970 Replacement Selection Sorting Techniques," M. A. Goetz, Spring .Iomt Computer Conference, pp. 599- 607, Spring, [21] Appl. No.: 95,205 1964.

52 US. (:1 ..444/1 f f' 51 1 1m. (:1. ..G06f 7/24, G06f 7/04 45mm Rlmds 5s 1 Field 6: Search ..340/172.5; 235/616 Mower-Fred lamb and Edward Hughes [56] References Cited 1 ABSTRACT UNITED STATES PATENTS A sequence of information items, each of which has or can be asslgned a numencal value, 15 sorted to obtain a 11st arranged 1 1 Armstrong in order of ascending or descending magnituda is accom. 3,444,523 5/1969 Dil'ks 34O/l72 5 plished by generating a difference table for the sequence and 3,428,946 2/1969 Batchel" 340/146 2 then interchanging various items of the sequence depending 3,380,029 4/1968 Goetz 340/172 5 on the entries f the difi table. 331L892 3/1967 OConnor et al. ..340/172.5 2,987,705 6/1961 Van Mechelen ..340/172.5 6 Claims, 10 Drawing Figures 1 Z neacisszo A; A; A? A2 12 1 (mfk, k) 1 9 1 r INTEELl/flA/G'E INTEEfl-MNGE 46'7/0N 7'0 I/IED N0 85 TAM 5N av Z'f, A/OA/E AIDA/E ,w/vs j NONE SEQU ENIE/EQ ENTE/ES 25.904 7' lA/' MIG/AWL $74705 0F SEQUENCE $'EQUENCE z/vwr SEQUENCE OF 3; ITEMS [Mr/44 ME E AND 5 70 ONE cm cuz ,4 re A Z fl/VD "STU/PE IN D/F'FEEENCE BUFFER IA/CkMEA/fg BYOA/' INVENTOR.

JAMES '4. S'C'HOOLEY" l KENNETH A. BOA/D ATTORNEY I I I I I I I v I I I v v I I PATENTEDMAY 91972 3,662,402

A SHEET 8 OF 8 THIS DOCUMENT DESCRIBES THE DIFFERENCE SORT PROCESS AS USED ON THE GE 625/635 SERIES COMPUTER, THE PROCESS IN THIS CASE IS CODED IN THE GMAP ASSEMBLY LANGUAGE FOR THE GE 625/635 COMPUTER,

EXECUTION OF THE CODE FROM "BDIF" THRU "BDOO" WILL BUILD A FINITE DIFFERENCE TABLE FROM INITIAL ENTRIES (SORT KEYS),

10 IF A NEGATIVE DIFFERENCE Is DETECTED, CODE AT "BDO3" wILL ll STORE THE Row AND COLUMN LOCATION FOR THIS DIFFERENCE IN 12 THE NEGATIVE DIFFERENCE BUFFER ("NEGBUF") -1= 1 3 A A A A A I A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A 1' A A A A A A 'c l4 BDIF NULL 15 STX7 BDOO 16 LXL7 N 17 CMPX7 2 ,DU

18 TNC C 19 sx 7 Q 20 SBX7 2 ,DU

21 SXL7 s 22 STZ M 23 A STZ L zER DIF COL COUNTER 24 LDQ N 25 MPY 2 ,DL

26 SBQ I,DL

27 STQ R 28 STZ K ZERO ENT COUNT 29 A08 M BUMP DIF COL COUNTER 30 LDA M 31 CMPA N IS M= N 32 TRC BDOO YEs, RET

33 BDOS LDA M M=DIF COUNT 34 CMPA I,DL

35 TZE BDO9 36 ADA K AR=ROw+DIF CNT 37 CMPA Q 38 TRC BDO1 YES IF TRA 39 BDIO LDA M 40 CMPA ,DL 15 THIS FIRST DIF 41 TZE BDOZ SET DELTA=2 43 EAx7 0,3 x7=LOw Row 44 EAX3 1,3 X3=HIGH Row 45 EAXO 0 SET DELTA =1 46 BDO4 XED DIFF,0

47 LXLA L 49 LDQ NEGBUF 50 ANQ -1,DL

51 CMPQ s 52 TRC BDOO ONLY STORE N-l ENTRIES IN NEGBUF I v I I PATENIEDHAY 9 I972 58 BDO9 62 BDO2 69 BDOl 79 BDO8 83 BDO7 85 BDO3 96 BDOO 97 DIFF 98 S'I'A ALS TMI

AOS TRA ADA CMPA TRC TRA EAXO Q MPY EAX3 EAX7 EAX3 TRA LDA ALS STCA LDXO STXO LDA ALS

STCA LDXO STXO LDA TTF STA TRA STA TRA LDA

AOS

ALS

ORA

LXLO ADXO STA AOS TRA LDA

RETURN TALE,O6 DIF TALE TALD, 10 BDO7 TALE,ID A

TALE, ID BDO8 NEGBUF NEGBUF 0,0 NEGBUF B005 4,DL SORT,1

SHEET 7 BF 8 ,lNl'I' IND 'IRA IF NEG SET DELTA =2 THIS CODE IS FOR DELTA =2 IF ON DIFF O X7=LOW ROW ADD 2 ,X3=HIGH ROW AR=DIFI ENTRIES MOVE NO. OF ENTRIES FOR TALLY STORE TALLY COUNT STORE ADD AR=DIFI ENTRIES SAVE TALLY COUNT SAVE ADD NO RUNOUT IF TRA STORE LAST ENT IN DIF AU=DIF COUNT =M AL=ROW ENT COUNT K STORE M AND ENT COUNT IN NEGBUF RET X3=HIGH ROW X7=LOW ROW X3=HIGH ROW X7=LOW ROW BACKGROUND OF THE INVENTION This invention relates generally to data processing methods and particularly to a method for sorting a sequence of information items.

Sorting may be defined as the process of arranging a set of information items in a uniform sequence as determined by the magnitudes of the individual items. See Richards, R.K., Arithmetic Operations in Digital Computers, D. Van Nostrand Co., Inc., 1955, page 295. Sorting is one of the basic data processing functions and is used in a variety of applications. For example, sorting is used for maintenance of business files such as inventory records and payroll records, for study and analysis of statistical data, for visual computer output such as printouts or CRT displays, and for maintenance of a data processing systems own internal data file.

1 It is desirable that any sorting method which is to be used in a data processing system be simple and efficient, i.e., that the method include few instructions or steps so that very little system memory is required to store the program implementation of the method and that the running time of the program implementation on the data processing system be as short as possible.

SUMMARY OF THE INVENTION It is an object of the present invention to provide a data sorting method which includes few instructions or steps.

It is another object of the present invention to provide a data sorting method which, when perfonned on a data processing system, operates to sort a sequence of information items in a relatively short period of time.

These" and other objects of the present invention are realized in a specific illustrative algorithm in which a difference table is generated for an arbitrarily ordered sequence of numerically valued items. Each negative entry of the difference table is noted by storing the entrys column number m and row number k. If, for each m and k stored, the (m k)th entry of the sequence of items has a magnitude less than that of the kth entry, then the two entries are interchanged. After all possible interchanges have been made, adifference table is generated for the new sequence. If no negative differences are found in this difference table, the process is terminated, otherwise the process is reiterated until a difference table with no negative differences isobtained. At the termination of the process, the sequence of n items will be arranged in order of ascending magnitude. I i a To obtain a sequence arranged in order of descending magnitude, positive differences of the difference tables are utilized rather than negative differences.

BRIEF DESCRIPTION OF THE DRAWINGS A complete understanding of the present invention and of the above and other advantages thereof may be gained from a consideration of the following detailed description of an illustrative embodiment thereof presented hereinbelow in connection with the accompanying drawings in which:

FIG. 1A, 1B, and 1C, with FIG. 1A positioned above FIG. 1B and FIG. 1B positioned above FIG. 1C, show a flow diagram representing a specific illustrative machine algorithm for practicing data processing in accordance with the present invention;

FIG. 2A shows an arbitrary sequence of n numbers which are to be sorted;

FIG. 2B shows the difference table generated for the sequence of numbers of FIG. 2A;

FIG. 2C shows which of the entries of the difference table of FIG. 2B are negative differences;

FIGS. 3A and 3B, and 3C show an illustrative computer program for implementing the algorithm represented in FIGS. 1A through 1C.

DETAILED DESCRIPTION The method of the present invention utilizes the so-called difference table," well-known in the field of mathematics. A difference table for a sequence of n numerically valued items is calculated by subtracting the first item in the sequence from the second, the second item in the sequence from the third, etc. until n-1 such differences are obtained. These differences comprise the first column of the difference table ordered in the order in which they were obtained, i.e., the difference between the first and second items of the sequence being the first entry in the column, the difference between the second and third items of the sequence being the second entry in the column, etc. Similarly, the differences between successive entries of this first column are then calculated to obtain the second column of the difference table. The process of obtaining the differences between entries of each column is continued until a final column containing but one entry is obtained. The entries of the difference table are generally represented by the symbol A where m designates the mth column of the difference table and k designates the kth entry of the column. Thus, A represents the kth entry of the mth column of a difference table. These conventions will be used in explaining the present invention.

The first step of the specific illustrative embodiment of the present invention shown in FIGS. 1A through 1C is to supply or input an arbitrarily ordered sequence of n items, each item having a numerical value, to a suitable data processing system on which the method is to be practiced (block 102 of FIG. 1A). The next step is to initialize or set each of two variables m and k to the value one as represented by block 104. The (k 1 )th entry of the (m 1 )th column of the difference table of the sequence of items is then calculated in accordance with block 106 of FIG. 1A and stored in a suitable difference bufier. A determination is then made as to whether this value is positive or negative (block 108). A negative value would be obtained if the first item of the sequence were larger than the second item. If the difference is negative, the algorithm moves to block 110 otherwise the algorithm moves to block 112.

In the step represented by block 110, the current values of m and k are stored'in a suitable negative difference" buffer. The two values are associated and as such are stored as a pair in the negative difference" bufier. (The purpose of designating the values as associated will become clear later.)

In the next step of the process, represented by block 112 of FIG. 1A, the value of the variable k is incremented by one. It is then determined whether the variable k is less than the value 11 corresponding to the number of entries in the sequence (block 114 of FIG. 18). If it is less, the algorithm returns to block 106 where a new entry in the difference table is calculated. At this stage of the description of the method, a new entry would be calculated and the process would be repeated until the variable k were incremented to a value equal to n at which time the algorithm would move from block 114 to block 116 of FIG.

In the step represented by block 116, the value of m, which was initially set equal to one, is incremented by one. A determination is then made as to whether m is less than n in accordance with block 118. Again, at this stage of the description of the method, m would be less than n and the algorithm would return to block 106 of FIG. 1A and further entries in the difference table would be calculated. After all entries of the difference table are calculated, at which time it would be determined that m is not less than n (block 118), the algorithm moves to block 120 of FIG. 1B.

In the step represented by block 120, a determination is made as to whether the negative difference buffer is empty. If it is empty, this means that there were no negative differences in the difi'erence table and that the sequence of n items is arranged in order of ascending magnitude as desired. The algorithm would then move to block 122 where the sequence of items would be printed out or otherwise made available to the user. At this stage of the description, of course, no sorting would have been done since the sequence as supplied to the data processing system would have been properly ordered.

If it is determined that the negative difference buffer is not empty, i.e., that the negative difference buffer contains stored pairs of values of m and k, then the algorithm moves to block 124. There, the variable m is initialized to the highest value of m stored in the negative difference buffer. In the next step,

represented by block 126, the variable k is initialized to the highest value of k associated with the highest value of m selected in the previous step. The value m k is then calculated (block 128 of FIG. 1C) and a determination is made as to whether the (m k)th entry of the sequence of n items is less than the kth entry (block 130). If it is less, the (m k)th entry and the kth entry are interchanged (block 132). If it is not less, the algorithm moves directly to block 134 of FIG. 1C.

In the step represented by block 134, the values of m and k of the negative difference buffer corresponding to the current values of the variables m and k are removed from the negative difference buffer. It is then determined whether or not the negative difference buffer is empty (block 136). If it is not empty, the algorithm returns to block 124 of FIG. 1B and the process of comparing the values of two more entries in the sequence is carried out. If the negative difference buffer is empty, indicating that all entries of the sequence which were designated by the items stored in the negative difference buffer (and now removed) have been examined, the algorithm returns to block 104 of FIG. 1A.

A new difference table is then generated in accordance with the description above and if the difference table contains no negative differences, the process is terminated in accordance with block 120 and 122 of FIG. 18 indicating that the sequence is now arranged in order of ascending magnitude. If the new difference table contains negative differences, then step 124 of FIG. 1A is commenced in accordance with the previous description.

The process of generating difference tables and comparing pairs of entries of the sequence is reiterated until a difference table which contains no negative differences is ultimately generated.

An example of the application of the method of the present invention to an arbitrarily ordered sequence of numbers will now be given. Consider the sequence of five numbers shown in FIG. 2A. As shown there, the first entry of the sequence is nine, the second is five, etc.

The first steps in processing the sequence of numbers of FIG. 2A in accordance with the method of the present invention would be to generate the difference table shown in FIG. 2B. The first entry of the first column of the difference table is obtained by subtracting nine from five, the second entry is obtained by subtracting five from three, etc. Steps 102 through 118 of FIGS. 1A and 1B would be the steps followed by a data processing system to generate the difference table of FIG. 2B.

As each entry of the difference table is generated, it is determined whether that entry is negative or positive (see step 108 of FIG. 1A). If the entry is negative, the values of m and k for that entry are stored in a negative difference buffer (step 110 of FIG. 1A). The negative entries of the difference table of FIG. 2B are indicated in FIG. 2C. Thus, in the course of processing the sequence of FIG. 2A, six pairs of values would be stored in the negative difference buffer of the data processing system. Each of these values would identify the column number and row number (in the difference table) of a negative difference.

Since the negative difference buffer would contain negative differences as a result of the difference table generated for the sequence of FIG. 2A, the process would move from block 120 of FIG. IE to block 124. There, a variable m would be initialized to the highest value of m stored in the negative difference buffer. The highest value of m so stored, as indicated in FIG. 2C, would be four. In the next step of the process, block 126, a variable k would be initialized to the highest value of k associated with m 4 in the negative difference buffer. In the present example, there is only one value of k associated with m 4 and that value is one. The next step of the process is to calculate m k 4 l 5 (block 128 of FIG. 1C). It is then determined whether the (m k 5)th entry of the sequence of FIG. 2A is less than the (k= l)th entry, in accordance with block 130 of FIG. 1C. Since the fifth entry of the sequence is two and the first entry is nine, the process would determine that the fifth entry is less than the first entry and the algorithm would move to block 132 of FIG. 1C. In accordance with block 132, the fifth entry of the sequence would be interchanged with the first entry.

In the next step of the process the values of m and k (4 and 1) would be removed from the negative difference buffer (block 134 of FIG. 1C) and the negative difference buffer would be examined to determine if it were empty (block 136). In the present example, the negative difference buffer would not be empty, so the process would return to block 124 of FIG. 1B and new values of m and k would be chosen from the negative difference buffer.

A summary of the steps taken in processing the sequence of FIG. 2A is shown in the table of FIG. 2D. The top row of the table indicates the negative differences of the difference table generated for the sequence. The second row of the table simply identifies the entries in the sequence which are to be compared for each m and k in the negative difference buffer. The third row indicates what action, if any, is to be taken on the sequence as a result of comparing the entries of the sequence. The last row of the table indicates the status of the sequence following the examination of different pairs of entries of the sequence. The original order of the sequence, as given in FIG. 2A, is shown in the second column and last row of the table.

Following the interchange of the fifth and first entries, as discussed above, the status of the sequence is as shown in the third column and last row of the table. As also shown in the table, the next value of m and k from the negative difference buffer to be examined is three and two respectively. Thus the entries to be examined are (m k)th or fifth entry and the kth or second entry. The fifth entry now is nine and the second entry is five. Since nine is not less than five, no interchange of the entries is made.

Examination of the values stored in the negative difference buffer continues with no interchange of entries being made until the values ofm l and k 2 are examined. Then, as indicated in the seventh column of the table of FIG. 20, since the third entry of the sequence in the sixth column which is three is found to be less than the second entry which is five, the entries are interchanged to obtain the sequence shown in the seventh column. The only remaining values in the negative difference buffer to be examined are m l and k 1. As indicated by the last column of the table of FIG. 2D, no interchange of entries is called for as a result of such examination. The ordering thus obtained as a result of applying the process of the present invention to the sequence of FIG. 2A is as shown in the last column of the last row of the table in FIG. 2D. As there shown, the sequence is arranged in order of ascending magnitude.

Processing the exemplary sequence of FIG. 2A would conclude with the generation of a new negative difference table and a determination that the table contains no negative differences (block of FIG. 1B). The sequence of items would then be made available for output to the user.

The method of the present invention may also be utilized to arrange a sequence of items in order of descending magnitude. In this case, however, positive differences in the difference table are utilized to determine which entries in the sequence are to be examined. Further, an interchange is made if the (m k)th entry is greater (rather than less) than the kth entry.

FIGS. 3A and 3B show an exemplary programming implementation of the present invention. The program is written in the soalled GMAP language described& for examples; in the General Electric 625/635 Programming Reference Manual, CPB l004F, for implementation on any General Electric 600 Series computer. Implementation of the present invention in the program of FIGS. 3A and 3B is apparent from an examination thereof and is therefore not described further.

It is to be understood that the above described embodiment is only illustrative to the application of the principles of the present invention. Modifications in this embodiment may be devised by those skilled in the art without departing from the spirit and scope of the invention.

What is claimed is:

1. In a data processing system, a method of sorting a sequence of information items comprising the steps of a. applying to said data processing system a sequence of information items, each of said items having a numerical value,

b. generating a difference table for said sequence of items, the entries of said table being generally designated by A where m designates the mth column of said table and k designates the kth row of the column,

c. storing the values of m and k associated with each negative difference of the most recently generated difierence table,

d. interchanging, for each stored pair of values of m and k, the (m k)th and kth entries of said sequence if the (m k)th entry has a value less than that of the kth entry.

2. A method as in claim 1 further comprising the steps of e. generating a new difference table for the sequence obtained at the conclusion of step (d),

f. terminating said method if no negative difference is present in said new difference table, and

(g) repeating steps (c) through (f) if there isa negative difference present in said new difference table.

3. A machine process for arranging a sequence of numerically valued information items in order of ascending magnitude comprising the steps of a. generating a difference table for said sequence of items,

b. storing in a storage means the column number and associated row number of each negative entry of the most recently generated difference table,

c. setting a variable m equal to the value of the highest valued column number stored in said storage means,

d. setting a variable k equal to the value of the highest valued row number associated with said highest valued column number,

e. interchanging the (m k)th and the kth entries of said sequence if the (m k)th entry has a value less than that of the kth entry,

f. removing from said storage means the column number and associated row number corresponding to the variable m and k respectively,

g. repeating steps (c) through (f) if said storage means is not empty, and

h. generating a difference table for the sequence resulting from the performance of steps (a) through (g) if said storage means is empty.

4. A process as in claim 3 further comprising the step of repeating steps (b) through (h) until a difference table is generated which contains no negative differences.

5. In a data processing system, a process of sorting a sequence of information items in order of descending magnitude comprising the steps of a. applying to said data processing system a sequence of information items, each of said items having a numerical value,

b. generating a difference table for said sequence of items, the entries of said table being generally designated by A,,.'", where m designates the mth column of said table and k designates the kth row of the column, c. storing the values of mand k associated with each positive difference of the most recently generated difference table,

d. interchanging, for each stored pair of values of m and k, the (m k)th and kth entries of said sequence if the (m k)th entry has a value greater than that of the kth entry.

6. A method an in claim 5 further comprising the steps of e. generating a new difference table for the sequence obtained at the conclusion of step (d),

f. terminating said method if no positive difference is present in said new difference table, and

g. repeating steps (0) through (f) if there is a positive difference present in said new difference table. 

1. In a data processing system, a method of sorting a sequence of information items comprising the steps of a. applying to said data processing system a sequence of information items, each of said items having a numerical value, b. generating a difference table for said sequence of items, the entries of said table being generally designated by Delta km, where m designates the mth column of said table and k designates the kth row of the column, c. storing the Values of m and k associated with each negative difference of the most recently generated difference table, d. interchanging, for each stored pair of values of m and k, the (m + k)th and kth entries of said sequence if the (m + k)th entry has a value less than that of the kth entry.
 2. A method as in claim 1 further comprising the steps of e. generating a new difference table for the sequence obtained at the conclusion of step (d), f. terminating said method if no negative difference is present in said new difference table, and (g) repeating steps (c) through (f) if there is a negative difference present in said new difference table.
 3. A machine process for arranging a sequence of numerically valued information items in order of ascending magnitude comprising the steps of a. generating a difference table for said sequence of items, b. storing in a storage means the column number and associated row number of each negative entry of the most recently generated difference table, c. setting a variable m equal to the value of the highest valued column number stored in said storage means, d. setting a variable k equal to the value of the highest valued row number associated with said highest valued column number, e. interchanging the (m + k)th and the kth entries of said sequence if the (m + k)th entry has a value less than that of the kth entry, f. removing from said storage means the column number and associated row number corresponding to the variable m and k respectively, g. repeating steps (c) through (f) if said storage means is not empty, and h. generating a difference table for the sequence resulting from the performance of steps (a) through (g) if said storage means is empty.
 4. A process as in claim 3 further comprising the step of repeating steps (b) through (h) until a difference table is generated which contains no negative differences.
 5. In a data processing system, a process of sorting a sequence of information items in order of descending magnitude comprising the steps of a. applying to said data processing system a sequence of information items, each of said items having a numerical value, b. generating a difference table for said sequence of items, the entries of said table being generally designated by Delta km, where m designates the mth column of said table and k designates the kth row of the column, c. storing the values of m and k associated with each positive difference of the most recently generated difference table, d. interchanging, for each stored pair of values of m and k, the (m + k)th and kth entries of said sequence if the (m + k)th entry has a value greater than that of the kth entry.
 6. A method an in claim 5 further comprising the steps of e. generating a new difference table for the sequence obtained at the conclusion of step (d), f. terminating said method if no positive difference is present in said new difference table, and g. repeating steps (c) through (f) if there is a positive difference present in said new difference table. 